home *** CD-ROM | disk | FTP | other *** search
- package icontrols.Data;
-
- import com.ms.ado.AdoException;
- import com.ms.ado.Field;
- import com.ms.ado.Recordset;
- import com.ms.ado.RecordsetEvent;
- import com.ms.ado.RecordsetEventHandler;
- import com.ms.com.Variant;
- import com.ms.wd.app.Message;
- import com.ms.wd.core.CancelEvent;
- import com.ms.wd.util.Debug;
- import com.ms.wd.win32.Windows;
-
- public class DataProvider {
- private static final float INVALID_RATIO = -23.23F;
- private static final int WM_DELAY_ACTION = 2476;
- private static final int DELAY_FIND_NEW_CURRENT_ROW = 1;
- private float m_cacheStartRatio = -23.23F;
- private float m_cacheRowRatioSize = -23.23F;
- private Object[] m_bookmarkCache = new Object[30];
- private int m_pageSize = 10;
- private int m_cacheSize = 30;
- private int m_currentRecordCacheIndex = -1;
- private int m_topRowCacheIndex = -1;
- private int m_bofCacheIndex = -1;
- private int m_eofCacheIndex = -1;
- private Object m_currentBookmark = null;
- private Recordset m_externalRecordset = null;
- private Recordset m_internalRecordset = null;
- private IDataConsumer m_dataConsumer = null;
- private int m_recordCount = -1;
- private boolean m_empty = false;
- private Recordset m_deleteRecordset = null;
- RecordsetEventHandler m_onWillChangeFieldHandler = null;
- RecordsetEventHandler m_onFieldChangeCompleteHandler = null;
- RecordsetEventHandler m_onWillChangeRecordHandler = null;
- RecordsetEventHandler m_onWillMoveHandler = null;
- RecordsetEventHandler m_onRecordChangeCompleteHandler = null;
- RecordsetEventHandler m_onWillChangeRecordsetHandler = null;
- RecordsetEventHandler m_onRecordsetChangeCompleteHandler = null;
- RecordsetEventHandler m_onMoveCompleteHandler = null;
- RecordsetEventHandler m_onEndOfRecordsetHandler = null;
-
- public void onWillChangeFieldHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onWillChangeFieldHandler(sender, event);
- }
-
- }
-
- public void onWillChangeRecordHandler(Object sender, RecordsetEvent event) {
- this.unhookEvents(this.m_externalRecordset);
- if (event.adReason == 2 && event.cRecords > 0) {
- Debug.trace("onWillChangeRecordHandler " + event.toString());
- Debug.trace(sender.getClass().getName());
- Recordset affected = null;
- if (sender == this) {
- affected = this.m_deleteRecordset;
- Debug.trace("count before clone: " + affected.getRecordCount());
- } else {
- affected = new Recordset(sender);
- }
-
- Debug.trace("count: " + affected.getRecordCount());
- if (this.m_dataConsumer != null) {
- Debug.trace("hit1");
- int asyncHwnd = this.m_dataConsumer.getAsyncPostHwnd();
- if (asyncHwnd != 0) {
- Debug.trace("hit2");
- this.m_dataConsumer.setAsyncPostMessage(2476);
- boolean currentDeleted = true;
- affected.moveFirst();
-
- for(int i = 0; i < event.cRecords; ++i) {
- Debug.trace("compare:" + bookmarkToLong(affected.getBookmark()) + " =?= " + bookmarkToLong(this.m_currentBookmark));
- if (bookmarksEqual(affected.getBookmark(), this.m_currentBookmark)) {
- Debug.trace("hit3");
- currentDeleted = true;
- break;
- }
-
- affected.moveNext();
- }
-
- if (currentDeleted) {
- Debug.trace("sending delay action message");
- this.m_currentBookmark = null;
- Windows.PostMessage(asyncHwnd, 2476, 1, 0);
- }
- }
- }
- }
-
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onWillChangeRecordHandler(sender, event);
- }
-
- this.hookEvents(this.m_externalRecordset);
- }
-
- public int getPageSize() {
- return this.m_pageSize;
- }
-
- public void setPageSize(int pageSize) {
- this.verifyValidCache();
- if (this.m_empty) {
- this.m_pageSize = pageSize;
- this.m_cacheSize = pageSize * 3;
- this.m_eofCacheIndex = -1;
- this.m_bofCacheIndex = -1;
- this.m_currentRecordCacheIndex = -1;
- this.m_cacheStartRatio = -23.23F;
- this.m_cacheRowRatioSize = -23.23F;
- } else {
- boolean updateRatio = false;
- if (this.m_cacheStartRatio != -23.23F) {
- updateRatio = true;
- }
-
- Object[] newCache = new Object[pageSize * 3];
- float topRow = -23.23F;
- Object bookmark = this.getBookmarkFromDisplayIndex(0);
- System.arraycopy(this.m_bookmarkCache, this.m_topRowCacheIndex, newCache, pageSize, Math.min(pageSize, this.m_pageSize));
- if (updateRatio) {
- topRow = this.getTopRowRatio();
- }
-
- this.m_pageSize = pageSize;
- this.m_cacheSize = pageSize * 3;
- this.m_eofCacheIndex = -1;
- this.m_bofCacheIndex = -1;
- this.m_currentRecordCacheIndex = -1;
- if (updateRatio) {
- this.m_cacheStartRatio = -23.23F;
- this.m_cacheRowRatioSize = -23.23F;
- }
-
- this.m_bookmarkCache = newCache;
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_currentRecordCacheIndex = this.getCacheIndexFromBookmark(this.m_currentBookmark);
- if (updateRatio) {
- this.m_cacheRowRatioSize = 1.0F / (float)this.getTotalRowCount();
- this.m_cacheStartRatio = topRow - (float)this.m_topRowCacheIndex * this.m_cacheRowRatioSize;
- }
-
- this.verifyValidCache();
- }
- }
-
- public void scrollToBottom() {
- if (!this.m_empty) {
- if (!this.fireViewScrollEvent()) {
- this.clearCache();
- this.m_internalRecordset.moveLast();
- this.m_bookmarkCache[this.m_pageSize + this.m_pageSize] = this.m_internalRecordset.getBookmark();
- this.m_internalRecordset.move(-1 * this.m_pageSize, this.m_bookmarkCache[this.m_pageSize + this.m_pageSize]);
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_bookmarkCache[this.m_topRowCacheIndex] = this.m_internalRecordset.getBookmark();
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(false, 0);
- }
-
- this.verifyValidCache();
- }
- }
- }
-
- public boolean fireViewScrollEvent() {
- CancelEvent cancel = new CancelEvent(false);
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onWillViewScroll(this, cancel);
- }
-
- return cancel.cancel;
- }
-
- public int getDisplayIndexFromBookmark(Object bookmark) {
- this.verifyValidCache();
- if (this.m_empty) {
- return -1;
- } else {
- if (this.m_topRowCacheIndex >= 0) {
- for(int i = this.m_topRowCacheIndex; i < this.m_cacheSize; ++i) {
- if (bookmarksEqual(bookmark, this.m_bookmarkCache[i])) {
- return i - this.m_topRowCacheIndex;
- }
-
- if (i >= this.m_topRowCacheIndex + this.m_pageSize) {
- break;
- }
- }
- }
-
- return -1;
- }
- }
-
- public float getTopRowRatio() {
- if (this.m_empty) {
- return 0.0F;
- } else if (this.m_cacheStartRatio != -23.23F) {
- int rowCount = this.getTotalRowCount();
- this.m_cacheRowRatioSize = 1.0F / (float)rowCount;
- this.m_internalRecordset.move(0, this.getBookmarkFromDisplayIndex(0));
- int abs = this.m_internalRecordset.getAbsolutePosition();
- float topRowRatio = (float)abs / (float)rowCount;
- this.m_cacheStartRatio = topRowRatio - (float)this.m_topRowCacheIndex * this.m_cacheRowRatioSize;
- return topRowRatio;
- } else {
- return this.m_cacheStartRatio + (float)this.m_topRowCacheIndex * this.m_cacheRowRatioSize;
- }
- }
-
- public int getTotalRowCount() {
- if (this.m_recordCount == -1) {
- this.m_recordCount = this.m_internalRecordset.getRecordCount();
- }
-
- return this.m_recordCount;
- }
-
- public boolean isBookmarksOrdered() {
- return this.m_externalRecordset.getProperties().getItem(86).getBoolean();
- }
-
- public static long bookmarkToLong(Object bookmark) {
- try {
- byte[] data = ((Variant)bookmark).toSafeArray().toByteArray();
- long temp = 0L;
- if (data.length > 8) {
- throw new IllegalArgumentException("bookmark can't be packed into a long");
- } else {
- for(int i = 0; i < data.length; ++i) {
- temp += (long)(data[i] << i * 8);
- }
-
- return temp;
- }
- } catch (ClassCastException var6) {
- try {
- int data = ((Variant)bookmark).toInt();
- return (long)data;
- } catch (ClassCastException var5) {
- throw new IllegalArgumentException("bookmark can't be packed into a long");
- }
- }
- }
-
- public void onFieldChangeCompleteHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onFieldChangeCompleteHandler(sender, event);
- }
-
- }
-
- public void onRecordChangeCompleteHandler(Object sender, RecordsetEvent event) {
- this.unhookEvents(this.m_externalRecordset);
- if (event.adReason == 2) {
- Debug.trace("onRecordChangeCompleteHandler for delete " + event.toString());
- Debug.trace(sender.getClass().getName());
- Recordset affected = null;
- if (sender == this) {
- affected = this.m_deleteRecordset;
- Debug.trace("count before clone(delete): " + this.m_deleteRecordset.getRecordCount());
- Debug.trace("count before clone(external): " + this.m_externalRecordset.getRecordCount());
- Debug.trace("count before clone(internal): " + this.m_internalRecordset.getRecordCount());
- } else {
- affected = new Recordset(sender);
- }
-
- Debug.trace("count: " + affected.getRecordCount());
- boolean foundGoodFirst = false;
- Object first = null;
- int currentTest = 0;
- Debug.trace("a1");
-
- while(!foundGoodFirst) {
- Debug.trace("b1");
-
- try {
- first = this.getDisplayRow(currentTest).getBookmark();
- } catch (AdoException var10) {
- first = null;
- }
-
- Debug.trace("b2");
- if (first != null) {
- foundGoodFirst = true;
-
- try {
- this.m_internalRecordset.move(0, first);
- } catch (AdoException var9) {
- foundGoodFirst = false;
- }
- } else {
- foundGoodFirst = false;
- }
-
- Debug.trace("b5");
- if (!foundGoodFirst) {
- ++currentTest;
- if (currentTest > this.getPageRowCount()) {
- Debug.trace("b6");
- break;
- }
- }
- }
-
- Debug.trace("a2");
- Debug.trace("clearing cache");
- this.clearCache();
- if (foundGoodFirst) {
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_bookmarkCache[this.m_topRowCacheIndex] = first;
- }
-
- this.verifyValidCache();
- if (this.m_empty) {
- Debug.trace("Cache blown!");
- }
-
- if (this.m_dataConsumer != null && this.m_currentBookmark != null) {
- Debug.trace("telling consumer to repaint");
- this.m_dataConsumer.onViewScrolled(false, -1);
- }
- }
-
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onRecordChangeCompleteHandler(sender, event);
- }
-
- this.hookEvents(this.m_externalRecordset);
- }
-
- public DataRow getCurrentRow() {
- this.verifyValidCache();
- if (this.m_empty) {
- return null;
- } else if (this.m_currentRecordCacheIndex == -1) {
- return new DataRow(-1, this.m_currentBookmark);
- } else {
- int displayIndex = this.m_currentRecordCacheIndex - this.m_topRowCacheIndex;
- if (displayIndex < 0 || displayIndex >= this.m_pageSize) {
- displayIndex = -1;
- }
-
- Object bookmark = this.m_bookmarkCache[this.m_currentRecordCacheIndex];
- if (bookmark == null) {
- this.fillCacheIndex(this.m_currentRecordCacheIndex);
- Object var10000 = this.m_bookmarkCache[this.m_currentRecordCacheIndex];
- }
-
- return new DataRow(displayIndex, this.m_bookmarkCache[this.m_currentRecordCacheIndex]);
- }
- }
-
- public void setCurrentRow(Object bookmark) {
- if (!this.m_empty) {
- this.m_externalRecordset.move(0, bookmark);
- }
- }
-
- private void clearCache() {
- for(int i = 0; i < this.m_cacheSize; ++i) {
- this.m_bookmarkCache[i] = null;
- }
-
- this.m_topRowCacheIndex = -1;
- this.m_currentRecordCacheIndex = -1;
- this.m_cacheStartRatio = -23.23F;
- this.m_cacheRowRatioSize = -23.23F;
- this.m_eofCacheIndex = -1;
- this.m_bofCacheIndex = -1;
- }
-
- public void moveFirst() {
- this.m_externalRecordset.moveFirst();
- }
-
- public void onMoveCompleteHandler(Object sender, RecordsetEvent event) {
- boolean updateDisplay = true;
- switch (event.adReason) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 11:
- updateDisplay = false;
- case 10:
- }
-
- if (updateDisplay) {
- this.m_currentBookmark = this.m_externalRecordset.getBookmark();
- this.m_currentRecordCacheIndex = this.getCacheIndexFromBookmark(this.m_currentBookmark);
- if (this.m_currentRecordCacheIndex != -1 && this.m_currentRecordCacheIndex >= this.m_pageSize && this.m_currentRecordCacheIndex <= this.m_cacheSize - this.m_pageSize) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(true, -1);
- }
- } else {
- this.scrollCurrentIntoView();
- }
- }
-
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onMoveCompleteHandler(sender, event);
- }
-
- }
-
- private void hookEvents(Recordset rs) {
- if (this.m_onWillChangeFieldHandler == null) {
- this.m_onWillChangeFieldHandler = new RecordsetEventHandler(this, "onWillChangeFieldHandler");
- rs.addWillChangeFieldHandler(this.m_onWillChangeFieldHandler);
- if (this.m_onFieldChangeCompleteHandler == null) {
- this.m_onFieldChangeCompleteHandler = new RecordsetEventHandler(this, "onFieldChangeCompleteHandler");
- }
-
- rs.addFieldChangeCompleteHandler(this.m_onFieldChangeCompleteHandler);
- if (this.m_onWillChangeRecordHandler == null) {
- this.m_onWillChangeRecordHandler = new RecordsetEventHandler(this, "onWillChangeRecordHandler");
- }
-
- rs.addWillChangeRecordHandler(this.m_onWillChangeRecordHandler);
- if (this.m_onWillMoveHandler == null) {
- this.m_onWillMoveHandler = new RecordsetEventHandler(this, "onWillMoveHandler");
- }
-
- rs.addWillMoveHandler(this.m_onWillMoveHandler);
- if (this.m_onRecordChangeCompleteHandler == null) {
- this.m_onRecordChangeCompleteHandler = new RecordsetEventHandler(this, "onRecordChangeCompleteHandler");
- }
-
- rs.addRecordChangeCompleteHandler(this.m_onRecordChangeCompleteHandler);
- if (this.m_onWillChangeRecordsetHandler == null) {
- this.m_onWillChangeRecordsetHandler = new RecordsetEventHandler(this, "onWillChangeRecordsetHandler");
- }
-
- rs.addWillChangeRecordsetHandler(this.m_onWillChangeRecordsetHandler);
- if (this.m_onRecordsetChangeCompleteHandler == null) {
- this.m_onRecordsetChangeCompleteHandler = new RecordsetEventHandler(this, "onRecordsetChangeCompleteHandler");
- }
-
- rs.addRecordsetChangeCompleteHandler(this.m_onRecordsetChangeCompleteHandler);
- if (this.m_onMoveCompleteHandler == null) {
- this.m_onMoveCompleteHandler = new RecordsetEventHandler(this, "onMoveCompleteHandler");
- }
-
- rs.addMoveCompleteHandler(this.m_onMoveCompleteHandler);
- if (this.m_onEndOfRecordsetHandler == null) {
- this.m_onEndOfRecordsetHandler = new RecordsetEventHandler(this, "onEndOfRecordsetHandler");
- }
-
- rs.addEndOfRecordsetHandler(this.m_onEndOfRecordsetHandler);
- }
- }
-
- public void onRecordsetChangeCompleteHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onRecordsetChangeCompleteHandler(sender, event);
- }
-
- }
-
- public void scrollToFirst() {
- if (!this.m_empty) {
- if (!this.fireViewScrollEvent()) {
- this.clearCache();
- this.m_internalRecordset.moveFirst();
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_bookmarkCache[this.m_topRowCacheIndex] = this.m_internalRecordset.getBookmark();
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(false, 0);
- }
-
- this.verifyValidCache();
- }
- }
- }
-
- public Object getBookmarkFromDisplayIndex(int displayIndex) {
- if (this.m_empty) {
- return null;
- } else {
- if (this.m_topRowCacheIndex == -1) {
- this.scrollToFirst();
- }
-
- int cacheIndex = this.m_topRowCacheIndex + displayIndex;
- if (cacheIndex < this.m_cacheSize) {
- if (this.m_bookmarkCache[cacheIndex] == null) {
- this.fillCacheIndex(cacheIndex);
- }
-
- return this.m_bookmarkCache[cacheIndex];
- } else {
- return null;
- }
- }
- }
-
- public void scrollCurrentIntoView() {
- if (!this.m_empty) {
- Object current = this.m_currentBookmark;
- int currentCacheIndex = this.m_currentRecordCacheIndex;
- int currentDisplayIndex = -1;
- if (currentCacheIndex == -1) {
- currentCacheIndex = this.getCacheIndexFromBookmark(current);
- this.m_currentRecordCacheIndex = currentCacheIndex;
- }
-
- if (currentCacheIndex != -1 && this.m_topRowCacheIndex != -1) {
- currentDisplayIndex = currentCacheIndex - this.m_topRowCacheIndex;
- if (-1 < currentDisplayIndex && currentDisplayIndex < this.m_pageSize) {
- return;
- }
- }
-
- if (!this.fireViewScrollEvent()) {
- if (currentCacheIndex > 0 && currentCacheIndex < this.m_cacheSize - this.m_pageSize) {
- int offset = -1;
- if (currentCacheIndex < this.m_topRowCacheIndex) {
- offset = this.m_topRowCacheIndex - currentCacheIndex;
- this.m_topRowCacheIndex = currentCacheIndex;
- } else {
- offset = this.m_topRowCacheIndex - (currentCacheIndex - (this.m_pageSize - 1));
- this.m_topRowCacheIndex = currentCacheIndex - (this.m_pageSize - 1);
- }
-
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(true, offset);
- }
- } else {
- this.clearCache();
- this.m_topRowCacheIndex = this.m_pageSize;
- if (currentCacheIndex > 0) {
- this.m_internalRecordset.move(-1 * (this.m_pageSize - 2), current);
- } else {
- this.m_internalRecordset.move(0, current);
- }
-
- this.m_bookmarkCache[this.m_topRowCacheIndex] = this.m_internalRecordset.getBookmark();
- this.m_internalRecordset.move(-1 * (this.m_pageSize - 1), this.m_bookmarkCache[this.m_topRowCacheIndex]);
- this.m_bookmarkCache[0] = this.m_internalRecordset.getBookmark();
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(false, 0);
- }
- }
-
- this.verifyValidCache();
- }
- }
- }
-
- public void move(DataRow row, int offset) {
- this.m_externalRecordset.move(offset, row.getBookmark());
- }
-
- public Field getReadField(String name) {
- try {
- return this.m_internalRecordset.getFields().getItem(name);
- } catch (AdoException var3) {
- return null;
- }
- }
-
- public void move(DataRow row) {
- this.m_externalRecordset.move(0, row.getBookmark());
- }
-
- public Object getBookmarkRelative(int offset, Object bookmark) {
- if (this.m_empty) {
- return null;
- } else {
- Object newBookmark = null;
- if (bookmark != null) {
- this.m_internalRecordset.move(offset, bookmark);
-
- try {
- newBookmark = this.m_internalRecordset.getBookmark();
- } catch (AdoException var5) {
- }
- }
-
- return newBookmark;
- }
- }
-
- public Field getReadField(int i) {
- try {
- return this.m_internalRecordset.getFields().getItem(i);
- } catch (AdoException var3) {
- return null;
- }
- }
-
- protected int getCacheIndexFromBookmark(Object bookmark) {
- this.verifyValidCache();
- if (this.m_empty) {
- return -1;
- } else {
- for(int i = 0; i < this.m_cacheSize; ++i) {
- Object compare = this.m_bookmarkCache[i];
- if (compare == null) {
- this.fillCacheIndex(i);
- compare = this.m_bookmarkCache[i];
- }
-
- if (bookmarksEqual(bookmark, compare)) {
- return i;
- }
- }
-
- return -1;
- }
- }
-
- private void optimizeCache() {
- if (!this.m_empty) {
- boolean updateRatio = false;
- float topRow = -23.23F;
- if (this.m_cacheStartRatio != -23.23F) {
- updateRatio = true;
- topRow = this.getTopRowRatio();
- }
-
- this.m_eofCacheIndex = -1;
- this.m_bofCacheIndex = -1;
- this.m_currentRecordCacheIndex = -1;
- if (updateRatio) {
- this.m_cacheStartRatio = -23.23F;
- this.m_cacheRowRatioSize = -23.23F;
- }
-
- int delta = this.m_pageSize - this.m_topRowCacheIndex;
- if (delta < 0) {
- for(int i = 0; i < this.m_cacheSize + delta; ++i) {
- this.m_bookmarkCache[i] = this.m_bookmarkCache[i - delta];
- }
-
- for(int i = this.m_cacheSize + delta; i < this.m_cacheSize; ++i) {
- this.m_bookmarkCache[i] = null;
- }
- } else {
- for(int i = this.m_cacheSize - 1; i >= delta; --i) {
- this.m_bookmarkCache[i] = this.m_bookmarkCache[i - delta];
- }
-
- for(int i = delta; i >= 0; --i) {
- this.m_bookmarkCache[i] = null;
- }
- }
-
- this.m_topRowCacheIndex = this.m_pageSize;
- if (updateRatio) {
- this.m_cacheRowRatioSize = 1.0F / (float)this.getTotalRowCount();
- this.m_cacheStartRatio = topRow - (float)this.m_topRowCacheIndex * this.m_cacheRowRatioSize;
- }
-
- this.m_currentRecordCacheIndex = this.getCacheIndexFromBookmark(this.m_currentBookmark);
- }
- }
-
- public boolean isBookmarksLiteral() {
- return this.m_externalRecordset.getProperties().getItem(67).getBoolean();
- }
-
- public static boolean rowsEqual(DataRow left, DataRow right) {
- return left != null && right != null ? bookmarksEqual(left.getBookmark(), right.getBookmark()) : false;
- }
-
- public DataProvider(Recordset external) {
- if (external == null) {
- throw new IllegalArgumentException("external can not be null");
- } else {
- this.m_externalRecordset = external;
- this.m_internalRecordset = (Recordset)this.m_externalRecordset.clone();
- this.m_currentBookmark = this.m_externalRecordset.getBookmark();
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_bookmarkCache[this.m_topRowCacheIndex] = this.m_currentBookmark;
- this.m_currentRecordCacheIndex = this.getCacheIndexFromBookmark(this.m_currentBookmark);
- this.hookEvents(this.m_externalRecordset);
- }
- }
-
- public void asyncMessageRecieved(Message msg) {
- if (msg.msg == 2476) {
- switch (msg.wParam) {
- case 1:
- Debug.trace("recieved delay action message");
- boolean needRepaint = this.m_currentBookmark == null;
-
- try {
- this.m_externalRecordset.moveNext();
- } catch (AdoException var4) {
- this.m_externalRecordset.moveLast();
- }
-
- if (this.m_externalRecordset.getEOF()) {
- this.m_externalRecordset.moveLast();
- }
-
- if (needRepaint && this.m_dataConsumer != null) {
- Debug.trace("forcing a repaint");
- this.m_dataConsumer.onViewScrolled(false, -1);
- }
- }
- }
-
- }
-
- public int getColumnCount() {
- return this.m_externalRecordset.getFields().getCount();
- }
-
- public int getPageRowCount() {
- if (this.m_empty) {
- return 0;
- } else if (this.m_eofCacheIndex != -1) {
- return this.m_topRowCacheIndex + this.m_pageSize > this.m_eofCacheIndex ? this.m_eofCacheIndex - this.m_topRowCacheIndex : this.m_pageSize;
- } else {
- for(int i = this.m_topRowCacheIndex + this.m_pageSize - 1; i >= this.m_topRowCacheIndex; --i) {
- Object current = this.m_bookmarkCache[i];
- if (current == null) {
- this.fillCacheIndex(i);
- current = this.m_bookmarkCache[i];
- }
-
- if (current != null) {
- return i - this.m_topRowCacheIndex;
- }
-
- if (this.m_eofCacheIndex >= 0) {
- return this.getPageRowCount();
- }
- }
-
- throw new RuntimeException("Failed to calculate pagerowcount");
- }
- }
-
- public Field getWriteField(int i) {
- try {
- return this.m_externalRecordset.getFields().getItem(i);
- } catch (AdoException var3) {
- return null;
- }
- }
-
- public Field getWriteField(String name) {
- try {
- return this.m_externalRecordset.getFields().getItem(name);
- } catch (AdoException var3) {
- return null;
- }
- }
-
- public void onEndOfRecordsetHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onEndOfRecordsetHandler(sender, event);
- }
-
- }
-
- public void onWillChangeRecordsetHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onWillChangeRecordsetHandler(sender, event);
- }
-
- }
-
- public String getFormattedData(DataRow row, Field field) {
- if (this.m_empty) {
- return null;
- } else {
- this.m_internalRecordset.move(0, row.getBookmark());
- String data = field.getString();
- return data == null ? "(null)" : data;
- }
- }
-
- public void onWillMoveHandler(Object sender, RecordsetEvent event) {
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onWillMoveHandler(sender, event);
- }
-
- }
-
- public void scroll(float ratio) {
- if (!this.m_empty) {
- if (!this.fireViewScrollEvent()) {
- if ((double)ratio == (double)0.0F) {
- this.scrollToFirst();
- } else if ((double)ratio == (double)1.0F) {
- this.scrollToBottom();
- } else {
- int rowCount = this.getTotalRowCount();
- this.clearCache();
- this.m_cacheRowRatioSize = 1.0F / (float)rowCount;
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_internalRecordset.setAbsolutePosition((int)(ratio * (float)rowCount));
- this.m_bookmarkCache[this.m_topRowCacheIndex] = this.m_internalRecordset.getBookmark();
- this.m_cacheStartRatio = ratio - (float)this.m_topRowCacheIndex * this.m_cacheRowRatioSize;
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(false, 0);
- }
- }
-
- this.verifyValidCache();
- }
- }
- }
-
- public void scroll(int offset, Object bookmark) {
- if (!this.m_empty) {
- Object newTopRow = null;
-
- try {
- newTopRow = this.getBookmarkRelative(offset, bookmark);
- } catch (Exception var11) {
- }
-
- if (newTopRow != null) {
- if (!this.fireViewScrollEvent()) {
- int displayIndexOfBase = this.getDisplayIndexFromBookmark(bookmark);
- int cacheIndexOfBase = -1;
- if (displayIndexOfBase != -1) {
- cacheIndexOfBase = displayIndexOfBase + this.m_topRowCacheIndex;
- }
-
- int cacheIndexOfDest = 0;
- if (cacheIndexOfBase > 0) {
- cacheIndexOfDest = cacheIndexOfBase + offset;
- }
-
- if (cacheIndexOfBase > 0 && cacheIndexOfDest > 0 && cacheIndexOfDest < this.m_cacheSize - this.m_pageSize) {
- int topRowOffset = this.m_topRowCacheIndex - cacheIndexOfDest;
- this.m_topRowCacheIndex = cacheIndexOfDest;
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(true, topRowOffset);
- }
-
- this.optimizeCache();
- } else {
- float currentRatio = -1.0F;
- if (displayIndexOfBase != -1) {
- currentRatio = this.m_cacheStartRatio;
- }
-
- Object newTop = null;
-
- try {
- this.m_internalRecordset.move(offset, bookmark);
- newTop = this.m_internalRecordset.getBookmark();
- } catch (AdoException var10) {
- }
-
- if (newTop != null) {
- this.clearCache();
- this.m_topRowCacheIndex = this.m_pageSize;
- this.m_bookmarkCache[this.m_topRowCacheIndex] = newTop;
- if ((double)currentRatio >= (double)0.0F) {
- }
-
- if (this.m_dataConsumer != null) {
- this.m_dataConsumer.onViewScrolled(false, 0);
- }
- } else if (offset > 0) {
- this.scrollToBottom();
- } else {
- this.scrollToFirst();
- }
- }
-
- this.verifyValidCache();
- }
- }
- }
- }
-
- public void setFormattedData(Field field, String data) {
- if (!this.m_empty) {
- field.setString(data);
- }
- }
-
- public void moveLast() {
- this.m_externalRecordset.moveLast();
- }
-
- private void fillCacheIndex(int cacheIndex) {
- if (!this.m_empty) {
- int filledCacheIndex = -1;
- boolean found = false;
- Debug.assert(cacheIndex >= 0 && cacheIndex < this.m_cacheSize, "Invalid cacheIndex");
- this.verifyValidCache();
- if ((this.m_bofCacheIndex < 0 || cacheIndex > this.m_bofCacheIndex) && (this.m_eofCacheIndex < 0 || cacheIndex < this.m_eofCacheIndex)) {
- for(int offset = 1; offset < this.m_cacheSize / 2; ++offset) {
- filledCacheIndex = cacheIndex - offset;
- if (filledCacheIndex > 0 && this.m_bookmarkCache[filledCacheIndex] != null) {
- found = true;
- break;
- }
-
- filledCacheIndex = cacheIndex + offset;
- if (filledCacheIndex < this.m_cacheSize && this.m_bookmarkCache[filledCacheIndex] != null) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- for(int i = 0; i < this.m_cacheSize; ++i) {
- if (this.m_bookmarkCache[i] != null) {
- filledCacheIndex = i;
- found = true;
- break;
- }
- }
- }
-
- if (!found) {
- throw new IllegalArgumentException("Invalid cache state. This error should never be seen, only here for debug purposes.");
- } else {
- this.m_internalRecordset.move(cacheIndex - filledCacheIndex, this.m_bookmarkCache[filledCacheIndex]);
- if (this.m_internalRecordset.getBOF()) {
- this.m_internalRecordset.move(0, this.m_bookmarkCache[filledCacheIndex]);
- int bofCacheIndex = filledCacheIndex;
-
- while(!this.m_internalRecordset.getBOF()) {
- this.m_internalRecordset.movePrevious();
- --bofCacheIndex;
- if (!this.m_internalRecordset.getBOF()) {
- this.m_bookmarkCache[bofCacheIndex] = this.m_internalRecordset.getBookmark();
- }
- }
-
- this.m_bofCacheIndex = bofCacheIndex;
- this.m_internalRecordset.move(0, this.m_bookmarkCache[filledCacheIndex]);
- } else if (this.m_internalRecordset.getEOF()) {
- this.m_internalRecordset.move(0, this.m_bookmarkCache[filledCacheIndex]);
- int eofCacheIndex = filledCacheIndex;
-
- while(!this.m_internalRecordset.getEOF()) {
- this.m_internalRecordset.moveNext();
- ++eofCacheIndex;
- if (!this.m_internalRecordset.getEOF()) {
- this.m_bookmarkCache[eofCacheIndex] = this.m_internalRecordset.getBookmark();
- }
- }
-
- this.m_eofCacheIndex = eofCacheIndex;
- this.m_internalRecordset.move(0, this.m_bookmarkCache[filledCacheIndex]);
- } else {
- this.m_bookmarkCache[cacheIndex] = this.m_internalRecordset.getBookmark();
- }
-
- }
- }
- }
- }
-
- public int getLastDisplayIndex() {
- this.verifyValidCache();
- if (this.m_empty) {
- return -1;
- } else {
- if (this.m_eofCacheIndex >= 0) {
- if (this.m_eofCacheIndex < this.m_topRowCacheIndex + this.m_pageSize) {
- return this.m_eofCacheIndex - this.m_topRowCacheIndex;
- }
- } else {
- for(int i = this.m_topRowCacheIndex + this.m_pageSize - 1; i >= this.m_topRowCacheIndex && this.m_bookmarkCache[i] == null; --i) {
- this.fillCacheIndex(i);
- if (this.m_eofCacheIndex >= 0) {
- return this.getLastDisplayIndex();
- }
- }
- }
-
- return -1;
- }
- }
-
- public void deleteRows(DataRow[] rows) {
- if (!this.m_empty) {
- if (rows != null) {
- this.m_deleteRecordset = (Recordset)this.m_externalRecordset.clone();
- Variant[] bookmarksList = new Variant[rows.length];
-
- for(int i = 0; i < rows.length; ++i) {
- bookmarksList[i] = (Variant)rows[i].getBookmark();
- }
-
- Variant bookmarks = new Variant();
- bookmarks.putVariantArray(bookmarksList);
- Object oldFilter = this.m_deleteRecordset.getFilter();
- Debug.trace("setting filter to bookmarks");
- this.m_deleteRecordset.setFilter(bookmarks);
- Debug.trace("deleting group");
- this.m_deleteRecordset.delete(2);
- this.m_deleteRecordset = null;
- }
- }
- }
-
- public void moveNext() {
- this.m_externalRecordset.moveNext();
- }
-
- public void setDataConsumer(IDataConsumer consumer) {
- this.m_dataConsumer = consumer;
- }
-
- private void unhookEvents(Recordset rs) {
- rs.removeWillChangeFieldHandler(this.m_onWillChangeFieldHandler);
- rs.removeFieldChangeCompleteHandler(this.m_onFieldChangeCompleteHandler);
- rs.removeWillChangeRecordHandler(this.m_onWillChangeRecordHandler);
- rs.removeWillMoveHandler(this.m_onWillMoveHandler);
- rs.removeRecordChangeCompleteHandler(this.m_onRecordChangeCompleteHandler);
- rs.removeWillChangeRecordsetHandler(this.m_onWillChangeRecordsetHandler);
- rs.removeRecordsetChangeCompleteHandler(this.m_onRecordsetChangeCompleteHandler);
- rs.removeMoveCompleteHandler(this.m_onMoveCompleteHandler);
- rs.removeEndOfRecordsetHandler(this.m_onEndOfRecordsetHandler);
- }
-
- public void movePrevious() {
- this.m_externalRecordset.movePrevious();
- }
-
- private void verifyValidCache() {
- for(int i = 0; i < this.m_cacheSize; ++i) {
- if (this.m_bookmarkCache[i] != null) {
- return;
- }
- }
-
- if (!this.m_empty) {
- Debug.trace("Cache State is becoming 'Empty'");
- Throwable t = new Throwable();
- t.printStackTrace();
- }
-
- this.m_empty = true;
- Debug.trace("Cache State is 'Empty'");
- }
-
- public DataRow getDisplayRow(Object bookmark) {
- this.verifyValidCache();
- return this.m_empty ? null : new DataRow(this.getDisplayIndexFromBookmark(bookmark), bookmark);
- }
-
- public DataRow getDisplayRow(int displayIndex) {
- this.verifyValidCache();
- if (this.m_empty) {
- return null;
- } else {
- Object bookmark = this.getBookmarkFromDisplayIndex(displayIndex);
- return bookmark != null ? new DataRow(displayIndex, bookmark) : null;
- }
- }
-
- public void refresh() {
- DataRow top = this.getDisplayRow(0);
- Object bookmarkTop = null;
- if (top != null) {
- bookmarkTop = top.getBookmark();
- }
-
- this.clearCache();
- this.m_topRowCacheIndex = this.m_pageSize;
- if (bookmarkTop == null) {
- try {
- this.m_internalRecordset.moveFirst();
- bookmarkTop = this.m_internalRecordset.getBookmark();
- } catch (AdoException var4) {
- bookmarkTop = null;
- }
- }
-
- this.m_bookmarkCache[this.m_topRowCacheIndex] = bookmarkTop;
- this.m_recordCount = -1;
- this.verifyValidCache();
- }
-
- public static boolean bookmarksEqual(Object left, Object right) {
- boolean match = true;
- if (left != null && right != null) {
- try {
- byte[] leftData = ((Variant)left).toSafeArray().toByteArray();
- byte[] rightData = ((Variant)right).toSafeArray().toByteArray();
- if (leftData.length == rightData.length) {
- for(int i = 0; i < leftData.length; ++i) {
- if (leftData[i] != rightData[i]) {
- match = false;
- break;
- }
- }
- } else {
- match = false;
- }
- } catch (ClassCastException var7) {
- try {
- int leftData = ((Variant)left).toInt();
- int rightData = ((Variant)right).toInt();
- if (leftData != rightData) {
- match = false;
- }
- } catch (ClassCastException var6) {
- match = false;
- }
- }
- } else {
- match = false;
- }
-
- return match;
- }
- }
-